package com.shopping.manager.service.imp;

import java.util.ArrayList;
import java.util.List;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import com.ccj.shopping_common.TreeNode;
import com.shopping.manager.mapper.TbItemCatMapper;
import com.shopping.manager.pojo.TbItemCat;
import com.shopping.manager.pojo.TbItemCatExample;
import com.shopping.manager.pojo.TbItemCatExample.Criteria;
import com.shopping.manager.service.ItemCatService;
@Service
public class ItemCatServiceImpl implements ItemCatService {
	
	@Autowired
	private TbItemCatMapper itemCatMapper;
	
	
	
	
	@Override
	public List<TreeNode> getItemCatList(long parentId) {
		// TODO Auto-generated method stub
		TbItemCatExample catExample=new TbItemCatExample();
		Criteria criteria=catExample.createCriteria();
		criteria.andParentIdEqualTo(parentId);
		
		List<TbItemCat> list=itemCatMapper.selectByExample(catExample);
		List<TreeNode> resultList = new ArrayList<>();

		for (TbItemCat tbItemCat : list) {
			TreeNode node =new TreeNode(tbItemCat.getId(), tbItemCat.getName(),tbItemCat.getIsParent()?"closed":"open");
			
			resultList.add(node);
		}
		
		
		//ctrl+shift+o，快速导入此文件中所有需要导入的类

		return resultList;
	}

}
